package myjava.algorithm.leetcode;

import java.util.Arrays;
import java.util.Comparator;

public class LargestNumber {
	public  static String largestNumber(int[] num) {
		String result = "";
		
		if(num == null || num.length == 0) return result;
		String[] str = new String[num.length];
		for(int i=0;i<num.length;i++)
			str[i] = String.valueOf(num[i]);
		
		Comparator<String> comparator = new Comparator<String>() {
			@Override
			public int compare(String str1,String str2)
			{
				String s1 = str1+str2;
				String s2 = str2 + str1;
				return s1.compareTo(s2);
			}
		};
		
		Arrays.sort(str,comparator);

		StringBuilder sb = new StringBuilder();
		
		for(int i=str.length -1;i>=0;i--)
		{
			sb.append(str[i]);
		}
		
		if(sb.charAt(0) == '0')
			return "0";
		
		return sb.toString();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] num = {33,34,5,9};
		System.out.println(largestNumber(num));
	}

}
